package com.opgea.crm.domain.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.opgea.crm.domain.entities.security.CrmUser;

@Entity
@Table(name="issuecomment") 
public class IssueComment implements Serializable {
	
	@Id
	@GeneratedValue
	@Column(name="id")
	private Long id;
	
	@Column(name="comment")
	private String comment;
	
	@JoinColumn(name="status")
	@ManyToOne
	private SetupsValue status;
	
	@JoinColumn(name="assignedTo", referencedColumnName="id")
	@ManyToOne
	private Employee assignedTo;
	
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="issue_id", referencedColumnName="id")
	private Issue issue;
	
	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="createdBy", referencedColumnName="username")
	private CrmUser createdBy;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="createdat")
	private Date createdAt;	
	
	public IssueComment() {
		super();
		// TODO Auto-generated constructor stub
	}

	public IssueComment(Long id, String comment, SetupsValue status,
			Employee assignedTo, Issue issue, CrmUser createdBy, Date createdAt) {
		super();
		this.id = id;
		this.comment = comment;
		this.status = status;
		this.assignedTo = assignedTo;
		this.issue = issue;
		this.createdBy = createdBy;
		this.createdAt = createdAt;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
	
	public void setIssue(Issue issue) {
		this.issue = issue;
	}

	public Issue getIssue() {
		return issue;
	}

	public void setStatus(SetupsValue status) {
		this.status = status;
	}


	public SetupsValue getStatus() {
		return status;
	}


	public void setAssignedTo(Employee assignedTo) {
		this.assignedTo = assignedTo;
	}


	public Employee getAssignedTo() {
		return assignedTo;
	}
	public void setCreatedBy(CrmUser createdBy) {
		this.createdBy = createdBy;
	}






	public CrmUser getCreatedBy() {
		return createdBy;
	}






	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}






	public Date getCreatedAt() {
		return createdAt;
	}






	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		IssueComment other = (IssueComment) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "IssueComment [id=" + id + ", comment=" + comment + ", status="
				+ status + ", assignedTo=" + assignedTo + ", issue=" + issue
				+ ", createdBy=" + createdBy + ", createdAt=" + createdAt + "]";
	}
}
